#include <REGX52.H>

sbit LCD_RS=P2^6;
sbit LCD_RW=P2^5;
sbit LCD_E=P2^7;
#define LCD_DataProt P0

void Delay();

void LCD_WriteCommand(unsigned char Command) {
	LCD_RS = 0;
	LCD_RW = 0;
	LCD_DataProt = Command;
	LCD_E = 1;
	Delay();
	LCD_E = 0;
	Delay();
}

void LCD_WriteData(unsigned char Data) {
	LCD_RS = 1;
	LCD_RW = 0;
	LCD_DataProt = Data;
	LCD_E = 1;
	Delay();
	LCD_E = 0;
	Delay();
}

void LCD_Init(void) {
	LCD_WriteCommand(0x38);
	LCD_WriteCommand(0x0c);
	LCD_WriteCommand(0x06);
	LCD_WriteCommand(0x01);
}

void LCD_ShowChar(unsigned char Line, unsigned char Column, unsigned char Char) {
	if (Line == 1) {
		LCD_WriteCommand(0x80|(Column - 1));
	} else {
		LCD_WriteCommand(0x80|(Column - 1) + 0x40);
	}
	LCD_WriteData(Char);
}

void Delay()		//@12.000MHz
{
	unsigned char i, j;

	i = 12;
	j = 169;
	do
	{
		while (--j);
	} while (--i);
}